/***************************************************************************
 创建者: 华磊
 开始时间: 2020.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2020.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef VREPCONTROL_H
#define VREPCONTROL_H

#include <QThread>
#include <QTimer>
#include "vrepobject.h"
#include "gSoapFoundation/soapStub.h"
//using namespace hmigsoapnamespace;

//支持几个机器人仿真
#define D_SUPPORT_SIMULATION_ROBOT_MAX 16

/**
 * @brief The VrepControl class vrep控制类
 */
class VrepControl : public QObject
{
    Q_OBJECT
public:
    explicit VrepControl(E_ECAT_REAL_VREP_MODE ioSmiulationModeIn,E_ECAT_REAL_VREP_MODE motorSmiulationModeIn,QObject *parent = 0);
    ~VrepControl();
public:
   int readVersion(std::vector <ComponentVersion> &componentVersionList);
   /**
    * @brief connectToVrep　连接模拟器
    * @param ip
    * @param _port　端口号
    * @return
    */
   int connectToVrep(QString _ip, int _port );

   /**
    * @brief disconnectFromVrep　断开连接
    */
   void disconnectFromVrep( );

signals:
    //void signal_dataChanged();
    void signal_msg(QString msg ,int code );

//public slots:
private:
    void timeOut_slot();



    /**
     * @brief displayMsg
     * @param msg　消息
     * @param code　消息代码或其他
     */
    void displayMsg( QString msg ,int code );

    /**
     * @brief demo 例子
     */
    void demo();
    void read();
    void write();

    void start(int ms=30);

    void quit();

    void* threadRun(void *);
    static void* threadTask( void* classPtr );
    void createThread();

public:

    bool isRun;
    QString vrepIp;
    int vrepPort;
    int clientID;//此机连接模拟器获得的ID, -1=not connnect
    volatile int motorSmiulationMode;//为保证安全，必须非时能状态下才能设置
    volatile int ioSmiulationMode;//为保证安全，必须非时能状态下才能设置

    VrepObject* vob[D_SUPPORT_SIMULATION_ROBOT_MAX];

private:
        ComponentVersion versionInfo;
        // QTimer timer;
         int interval;//ms
         QTimer *timer;

};

#endif // VREPCONTROL_H
